home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 17681 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.2 KB  |  83 lines

  1. Path: prodigy.com!usenet
  2. From: NEKU72A@prodigy.com (Brian Munroe)
  3. Newsgroups: comp.lang.c++
  4. Subject: Help! What's wrong with this?
  5. Date: 17 Apr 1996 06:26:43 GMT
  6. Organization: Prodigy Services Company  1-800-PRODIGY
  7. Distribution: world
  8. Message-ID: <4l22v3$1beo@useneta1.news.prodigy.com>
  9. NNTP-Posting-Host: innugap1-int.news.prodigy.com
  10. X-Newsreader: Version 1.2
  11.  
  12. I'm trying to learn C++ and I've run into a strange problem in the 
  13. following code.
  14.  
  15. int const ADD_LEN = 40;
  16. int main()
  17. {
  18.   struct cust_list {
  19.     char name[ADD_LEN];
  20.     char add1[ADD_LEN];
  21.     char add2[ADD_LEN];
  22.     char add3[ADD_LEN];
  23.   } customer;
  24.   int flag;
  25.  
  26.   void get_customer_info(char temp[ADD_LEN], int flag);
  27.  
  28.   for (flag=0; flag<4; flag++)
  29.   { switch (flag)
  30.     { case 0: get_customer_info(customer.name, flag); break;
  31.       case 1: get_customer_info(customer.add1, flag); break;
  32.       case 2: get_customer_info(customer.add2, flag); break;
  33.       case 3: get_customer_info(customer.add3, flag); break;
  34.       default: exit(1);
  35.     }
  36.   }
  37.   return 0;
  38. }
  39.  
  40. void get_customer_info(char temp[ADD_LEN], int flag)
  41. { int answer;
  42.   int len;
  43.   clrscr();
  44.   switch (flag)
  45.   { case 0:
  46.      cout << "Enter the bidder's name in one of the following forms.\n";
  47.      cout << "  Person: LAST NAME, FIRST NAME\n";
  48.      cout << "  Business: COMPANY NAME\n\n";
  49.      break;
  50.     case 1:
  51.      cout << "\nEnter first line of address\n";
  52.      break;
  53.     case 2:
  54.      cout << "\nEnter second line of address\n";
  55.      break;
  56.     case 3:
  57.      cout << "\nEnter third line of address\n";
  58.      break;
  59.     default:
  60.      exit(1);
  61.   }
  62.   cin >> temp;
  63.   len = strlen(temp);
  64.   if (len < ADD_LEN)
  65.    { strncat(temp, "                                        ",ADD_LEN-
  66. len);}
  67.   temp[ADD_LEN-1] = '\0';
  68.   return;
  69. }
  70.  
  71. When I run this all 4 prompts are outputted (Is that a word?), but only 
  72. input for the name and second line are  accepted. The input line doesn't 
  73. accept input for the first and third lines. I'm guessing that there is a 
  74. return character caught in the input buffer after I input the name and 
  75. second address lines and it's read in for the first and third lines. If 
  76. so, how do I get it out of the buffer and what the heck is it doing there 
  77. in the first place !?
  78.  
  79. Thanks for your help.
  80.  
  81.  
  82.  
  83.